﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ChoJu.Single.ViewModel;
using ChongJu.Camera;

namespace ChoJu.Single.Views
{
    /// <summary>
    /// RatingView.xaml 的交互逻辑
    /// </summary>
    public partial class RatingView : UserControl
    {

        private RatingVM _vm; 
        public RatingView()
        {
            InitializeComponent();

            _vm = new RatingVM();
            DataContext = _vm;
            _vm.FocusLastItem += AutoScroll;
            gridCount.Visibility = Visibility.Collapsed;
        }

        /// <summary>
        /// 滚动条自动滚动
        /// </summary>
        private void AutoScroll()
        {
            this.Dispatcher.Invoke(() =>
            {
                if (lstLog.Items.Count > 0)
                    lstLog.ScrollIntoView(lstLog.Items[lstLog.Items.Count - 1]);
            });
        }

        private void Mouse_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
            {
               if(gridCount.Visibility == Visibility.Visible)
                    gridCount.Visibility = Visibility.Collapsed;
                else
                    gridCount.Visibility = Visibility.Visible;
            }
        }

        private void Border_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
                new SiteInfoView().ShowDialog();
            //else
                //Camera.Instance.TakeOne();
        }

        private void Border_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            Camera.Instance.TakeOne();
        }
    }
}
